package com.example.androidaudiovideodemo

import android.opengl.GLES20
import android.opengl.GLSurfaceView
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

/**
 *
 * author: renbing
 *
 * date: 2022/1/14
 *
 * des:
 */
class MyGLRenderer : GLSurfaceView.Renderer {
    private var mTriangle: Triangle? = null

    override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
        GLES20.glClearColor(1f,1f,1f,1f)
        mTriangle = Triangle()
    }

    override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
        GLES20.glViewport(0,0,width, height)
    }

    override fun onDrawFrame(gl: GL10?) {
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
        mTriangle?.draw()
    }

    companion object{
        fun loadShader(type: Int,shaderCode: String): Int{
            //根据type创建着色器
            val shader = GLES20.glCreateShader(type)
            //加载资源到着色器
            GLES20.glShaderSource(shader,shaderCode)
            //编译
            GLES20.glCompileShader(shader)
            return shader
        }
    }
}